#include "asmhighlighter.h"

AsmHighlighter::AsmHighlighter(QTextDocument *parent)
    :QSyntaxHighlighter(parent){

}

void AsmHighlighter::highlightBlock(const QString &text)
{
    QTextCharFormat insFormat, numFormat;
    insFormat.setForeground(Qt::blue);
    numFormat.setForeground(Qt::darkYellow);
    QString insPattern = "LDA|ADD|SUB|NOT|AND|OR|OUT|HLT";
    QString numPattern = "\\s[0#]\\w+";
    QRegExp insExp(insPattern), numExp(numPattern);
    int index = text.indexOf(insExp);
    while (index >= 0) {
        int length = insExp.matchedLength();
        setFormat(index, length, insFormat);
        index = text.indexOf(insExp, index + length);
    }
    index = text.indexOf(numExp);
    while (index >= 0) {
        int length = numExp.matchedLength();
        setFormat(index, length, numFormat);
        index = text.indexOf(numExp, index + length);
    }
}

